package com.zat.mes.andrmes.utils;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;

/**
 * @author zy
 */
public class SpannableStrUtil {

    public static SpannableString getColorSpannable(String message, int start, int end, int color) {
        SpannableString spannableString = getColorSpannable(message, start, end, color, 0);
        return spannableString;
    }

    public static SpannableString getColorSpannable(int color, String message, String... mate) {
        SpannableString spannableString = new SpannableString(message);
        //ForegroundColorSpan span = new ForegroundColorSpan(color);
        for (int i = 0; i < mate.length; i++) {
            int start = message.indexOf(mate[i]);
            if (start >= 0) {
                spannableString.setSpan(new ForegroundColorSpan(color), start, start + mate[i].length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        return spannableString;
    }

    public static SpannableString getColorSpannable(String message, int start, int end, int color, int size) {//dip
        SpannableString spannableString = new SpannableString(message);
        ForegroundColorSpan span = new ForegroundColorSpan(color);
        spannableString.setSpan(span, start, end,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        if (size > 0) {
            spannableString.setSpan(new AbsoluteSizeSpan(size, true), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableString;
    }

    public static SpannableString getSizeSpannable(String meassage, int start, int end, int size) {
        SpannableString spannableString = new SpannableString(meassage);
        spannableString.setSpan(new AbsoluteSizeSpan(size, true), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
}
